/**
 * 振动开关与调用
 * **/
import Tool from "./Tool";

const {ccclass, property} = cc._decorator;

@ccclass
export default class VibrationManage {

    static isOpen = null;

    static init(){
        let b1 = (Tool.getData("vibOpen")|| "").toString();
        VibrationManage.isOpen = (b1 == "1" || b1 == null|| b1 == "") ? true:false;
    }

    static save(is){
        console.log("set vibration",is);
        VibrationManage.isOpen = is;
        let str = is? '1' : '0';
        Tool.saveData("vibOpen",str);
    }

    /**
     *
     * @param type 1短振动 2长振动
     */
    static vivrate(type?){
        if(VibrationManage.isOpen == null){
            VibrationManage.init();
        }
        if(!VibrationManage.isOpen){
            return
        }
        if(type == null){
            type = 1;
        }
        if(typeof (wx ) != "undefined"){
            if(type == 1){
                wx.vibrateShort({})
            }else{
                wx.vibrateLong({})
            }
        }
    }

}
